﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Reflection;
using NUnit.Framework;


namespace NUnit4PowerShell
{
    [TestFixture]
    public class ParametrizedFixture
    {
        public ParametrizedFixture()
        {
            InitializeFixture();
        }

        private static IList<string> _functionsToTestList;
        private readonly string _testFilePath = FixtureProvider.GetOne();

        #region Properties
        /// <summary>
        /// Provide the function list to test inside this fixture
        /// </summary>
        /// <returns></returns>
        public IEnumerable<string> FunctionsToTest()
        {
            if (_functionsToTestList == null)
            {
                throw new NullReferenceException("Functions list is null");
            }
            return _functionsToTestList;
        }
        #endregion


        private void InitializeFixture()
        {
            // Get function to test in this fixture
            _functionsToTestList = GetFunctions(_testFilePath);
        }

        static private IList<string> GetFunctions(string file)
        {
            // Find the test to execute. For instance :
            var testsToBeDone = new List<string>();
            for (int i=0; i < 3; i++ )
            {
                testsToBeDone.Add("Test" + i);
            }
            // But in my project : this list was depending of the property _testFilePath
            return testsToBeDone;
        }

        [Test]
        [TestCaseSource("FunctionsToTest")]
        public void PowerShell_Tests(string functionToTest)
        {
            // Tests to execute
        }
    }
}
